package grafica;

import java.awt.Color;
import java.awt.Graphics;

public class Dardo2 extends DardoGrafico {

	protected Dardo2(int tempo, int affaticamento, int gittata, Color color) {
		super(tempo, affaticamento, gittata, color);
	}

	@Override
	protected void disegna(Graphics g) {
		int[] xPoints, yPoints;
		float a1 = getDestinazione()[0] - getStartPoint()[0];
		float a2 = getDestinazione()[1] - getStartPoint()[1];

		float f = (float) Math.sqrt(a1 * a1 + a2 * a2);

		a1 = a1 / f;
		a2 = a2 / f;
		int nPoints = (int) f;
		xPoints = new int[nPoints];
		yPoints = new int[nPoints];
		float angle = (float) Math.atan(a2 / a1);
		float cangle = (float) Math.cos(angle);
		float sangle = (float) Math.sin(angle);
		for (float i = 0; i < nPoints; i++) {
			xPoints[(int) i] = (int) (a1 * i + getStartPoint()[0] - 10
					* Math.sin(i / 4) * sangle);
			yPoints[(int) i] = (int) (a2 * i + getStartPoint()[1] + 10
					* Math.sin(i / 4) * cangle);
		}
		g.drawPolyline(xPoints, yPoints, nPoints);
	}

}
